<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //es6允许箭头函数

        //正常写法
        var fn1 = function(x, y){
            return x+y;
        }

        var fn2 = (x,y) => x+y;
        var fn3 = x => x;
        var fn4 = () => 10;
        var fn5 = (x, y) => ({y,x});
        console.log(fn5(10, 20));

        //对于普通函数来说，内部this指向所在的对象，但是箭头函数没有this，this会指向上一层对象
        var name = "itbaizhan";
        var user = {
            name :"iwen",
            getName(){
                setTimeout(() => {
                    console.log(this.name);
                })
            }
        }
        user.getName()




    </script>
</body>
</html>